<template>
	<view class="content">
		<u-steps style="margin-top: 50rpx;" activeColor="#F85F69" :current="current">
			<u-steps-item :title="$t('create')"></u-steps-item>
			<u-steps-item :title="$t('success')"></u-steps-item>
		</u-steps>
		<view class="register_con" v-if="current==0">
			<view class="options">
				<label>*</label>{{$t('account')}}
			</view>
			<view class="form">
				<view class="con">
					<u-icon name="account" color="#999" :size="iconSize"></u-icon>
					<u-input v-model="account" :placeholder="$t('account_alert')" border="none" :fontSize="fontSize"></u-input>
				</view>
			</view>
			<view class="options">
				<label>*</label>{{$t('password')}}
			</view>
			<view class="form">
				<view class="con">
					<u-icon name="lock" color="#999" :size="iconSize"></u-icon>
					<u-input v-model="password" password :placeholder="$t('password_alert')" border="none" :fontSize="fontSize">
					</u-input>
				</view>
				<view class="con">
					<u-icon name="lock" color="#999" :size="iconSize"></u-icon>
					<u-input v-model="password2" password :placeholder="$t('password_alert2')" border="none" :fontSize="fontSize">
					</u-input>
				</view>
			</view>
			<view class="options">
				<label>*</label>{{$t('reg_code')}}
			</view>
			<view class="form">
				<view class="con">
					<u-icon name="email" color="#999" :size="iconSize"></u-icon>
					<u-input v-model="regcode" :placeholder="$t('reg_code_alert')" border="none" :fontSize="fontSize"></u-input>
				</view>
			</view>
			<view class="agreement">
				<checkbox :checked="isRead" color="#f86e47" @click="funRead"></checkbox>
				<view>
					{{$t('login_agree')}}
					<text>《{{$t('service_agreement')}}》</text>
				</view>
			</view>
			<button @click="funRegister">{{$t('register')}}</button>
			<view class="reg">
				已有帐号？<text @click="goLogin">{{$t('go_login')}}</text>
			</view>
		</view>
		<view class="register_con" v-else-if="current==1">
			<view class="nodata_con">
				<u-icon name="checkmark-circle-fill" size="80rpx" color="#31a64d"></u-icon>
				<text>{{msg}}</text>
			</view>
			<button style="margin-top: 150rpx;" @click="goLogin">立即登录</button>
		</view>
		<!--刷新-->
		<view class='loadind_con' v-if="isLoading">
			<view class="loading">
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
				<view class="loading-bar"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import valid from '../../static/valid.js';

	export default {
		data() {
			return {
				isLoading: false, //是否正在加载
				current: 0, //步骤 0创建帐号 1注册成功
				iconSize: '50rpx', //图标大小
				fontSize: '30rpx', //文本框字体大小
				account: '', //帐号名
				password: '', //密码
				password2: '', //确认密码
				regcode: '', //注册码
				isRead: false, //是否阅读
				msg: '', //注册提示信息
			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('register')
			})
		},
		onLoad() {

		},
		methods: {
			//去登录
			goLogin() {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];

				if (prevPage.route == 'pages/login/index')
					uni.navigateBack();
				else
					this.fun_navigateTo('/pages/login/index');
			},
			//点击注册
			funRegister() {
				var _this = this;

				//验证
				if (_this.fun_validate(_this.account == '', "请输入帐号名") ||
					_this.fun_validate(_this.password == '', "请输入密码") ||
					_this.fun_validate(_this.password2 == '', "请再次输入密码") ||
					_this.fun_validate(_this.password != _this.password2, "2次密码输入不一致") ||
					_this.fun_validate(_this.regcode == '', "请输入注册码") ||
					_this.fun_validate(_this.isRead == false, "请阅读协议并勾选")) {
					return;
				}

				//注册
				_this.fun_request("/Api/Member/Register", {
					account: _this.account,
					password: _this.password,
					regcode: _this.regcode
				}, function(res) {
					//第二步
					_this.current = 1;
					_this.msg = res.msg;
				}, function(res) {
					_this.fun_showToast(res.msg);
				});
			},
			//阅读
			funRead() {
				this.isRead = this.isRead ? false : true;
			},
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 30rpx 0 0;
	}

	.register_con {
		padding: 50rpx 15%;

		.title {
			font-size: 32rpx;
			border-bottom: 1rpx solid #d3d3d3;
			padding: 20rpx 0;
		}

		.options {
			color: #8c8a8b;
			font-size: 30rpx;
			display: flex;
			align-items: center;
			margin-top: 30rpx;

			label {
				color: #F85F69;
				margin-right: 5rpx;
			}
		}

		.form {
			.con {
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-top: 25rpx;
				padding: 0 0 0 3%;
				border: 1rpx solid #d6d6d6;
				border-radius: 50rpx;
				height: 90rpx;
				overflow: hidden;

				.u-icon {
					margin-right: 10rpx;
				}

				.code {
					background-color: #F85F69;
					font-size: 28rpx;
					color: #fff;
					height: 90rpx;
					line-height: 90rpx;
					padding: 0 15rpx;
				}

				.text {
					color: #666;
					flex: 1;
				}
			}
		}

		.agreement {
			display: flex;
			align-items: center;
			margin-top: 30rpx;
			font-size: 30rpx;
			color: #666;

			checkbox {
				transform: scale(0.8);
			}

			view {

				text {
					color: #F85F69;
				}
			}
		}

		button {
			background: linear-gradient(to right, #F85F69, #ff6c45) !important;
			color: #fff;
			font-size: 30rpx;
			height: 90rpx;
			line-height: 90rpx;
			margin-top: 50rpx;
			border-radius: 50rpx;
		}

		.reg {
			text-align: center;
			font-size: 28rpx;
			margin-top: 30rpx;
			color: #666;

			text {
				color: #F85F69;
			}
		}
	}
</style>
